package com.sensePlusVR.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sensePlusVR.base.BaseDialog;
import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.AppUtil;
import com.sensePlusVR.utils.DensityUtil;
import com.sensePlusVR.utils.FileConvertUtil;
import com.sensePlusVR.utils.MyDialogUtil;
import com.sensePlusVR.utils.MyLog;

public class MemoryLessDialog extends BaseDialog implements android.view.View.OnClickListener{
	private static final String TAG = MemoryLessDialog.class.getSimpleName();
	private Context context;
	private long gameSize;
	private LinearLayout memory_linear;
	private TextView memory_out_of_tv;
	private ImageView memory_del_iv;
	
	public MemoryLessDialog(Context context,long gameSize) {
		super(context,R.style.FullScreen_Dialog_Half_Tran);
		this.context = context;
		this.gameSize = gameSize;
		init();
	}

	private void init() {}
	
	@Override
	protected void onStart() {
		super.onStart();
		//强制隐藏底部导航栏，否则如果此时导航栏存在则会遮挡底部UI
		AppUtil.hideVirtualKey(this);
	}
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_memory_less);
		
		memory_linear = (LinearLayout) findViewById(R.id.memory_linear);
		memory_out_of_tv = (TextView) findViewById(R.id.memory_out_of_tv);
		memory_del_iv = (ImageView) findViewById(R.id.memory_del_iv);
		
		memory_del_iv.setOnClickListener(this);
		
		if(!AppUtil.isNavigationBarShow((Activity)context)){
			int paddingLTR = DensityUtil.dip2px(context, 20);
			int paddingB = DensityUtil.dip2px(context, 40);
			memory_linear.setPadding(paddingLTR, paddingLTR, paddingLTR, paddingB);
		}
		
		String gameSizeFormat = FileConvertUtil.getMbGbFileSize(gameSize);
		MyLog.d(TAG, "gameSizeFormat : " + gameSizeFormat);
		String needSpaceTemp = context.getResources().getString(R.string.memory_out_of_memory,gameSizeFormat);
		Spanned needSpace = Html.fromHtml(needSpaceTemp);
		memory_out_of_tv.setText(needSpace);
		
	}
	
	@Override
	public void show() {
		super.show();
		MyDialogUtil.setDialogFullScreen(context, this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.memory_del_iv:
			dismiss();
			break;
		}
		
	}

}
